//
//  SelectClassV.m
//  LoveDraw
//
//  Created by 零零壹 on 2017/7/19.
//  Copyright © 2017年 梁晨. All rights reserved.
//

#import "SelectClassV.h"
#import "SelectClassTableViewCell.h"
#import "SelectTeacherModel.h"

@implementation SelectClassV

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

/*@property(nonatomic,strong)UITableView *classV;
 @property(nonatomic,strong)NSMutableArray *listArr;*/

-(NSMutableArray *)listArr
{
    if (!_listArr) {
        _listArr = [NSMutableArray array];
    }
    return _listArr;
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        self.TopimageV = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"tongjiimageV"]];
        [self addSubview:self.TopimageV];
        self.backgroundColor = [[UIColor blackColor]colorWithAlphaComponent:0.2];
        self.classV = [[UITableView alloc]initWithFrame:CGRectZero style:(UITableViewStyleGrouped)];
        [self addSubview:self.classV];
        self.classV.backgroundColor = [UIColor whiteColor];
        self.classV.delegate = self;
        self.classV.separatorStyle = 0;
        self.classV.dataSource = self;
        [self.classV registerNib:[UINib nibWithNibName:@"SelectClassTableViewCell" bundle:nil] forCellReuseIdentifier:@"SelectClassTableViewCell"];
        self.classV.estimatedSectionHeaderHeight = 0;
        self.classV.estimatedSectionFooterHeight = 0;
        [self addSubview:self.classV];
        self.topLabel = [[UILabel alloc]init];
        self.topLabel.text = @"请选择班级";
        [self.TopimageV addSubview:self.topLabel];
        self.topLabel.textColor = [UIColor whiteColor];
        self.topLabel.font = [UIFont systemFontOfSize:17];


        self.bottomV = [[UIView alloc]init];
        self.topV = [[UIView alloc]init];
        self.leftV = [[UIView alloc]init];
        self.rightV = [[UIView alloc]init];

        [self addSubview:self.bottomV];
         [self addSubview:self.topV];
         [self addSubview:self.leftV];
         [self addSubview:self.rightV];

        UITapGestureRecognizer *topTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenV)];
        UITapGestureRecognizer *leftTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenV)];
        UITapGestureRecognizer *rightTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenV)];
        UITapGestureRecognizer *bottomTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenV)];

        [self.topV addGestureRecognizer:topTap];
         [self.bottomV addGestureRecognizer:bottomTap];
         [self.leftV addGestureRecognizer:leftTap];
         [self.rightV addGestureRecognizer:rightTap];

    }
    return self;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return FLT_MIN;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return FLT_MIN;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.listArr.count;
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SelectTeacherModel *model = self.listArr[indexPath.row];
    SelectClassTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SelectClassTableViewCell" forIndexPath:indexPath];
    cell.titleL.text = model.coursename;
    cell.selectionStyle = 0;
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    SelectTeacherModel *model = self.listArr[indexPath.row];
    self.myselect(model.cid,model.sid);
    self.alpha = 0;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    [self.classV mas_makeConstraints:^(MASConstraintMaker *make)
    {
        make.centerX.equalTo(self.mas_centerX);
        make.centerY.equalTo(self.mas_centerY);
        make.width.mas_equalTo(KscreenW*4/5);
        make.height.mas_equalTo(60*2+80);
    }];
    [self.TopimageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(self.classV.mas_top);
        make.width.equalTo(self.classV.mas_width);
        make.height.mas_equalTo(60);
    }];
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.TopimageV.mas_centerX);
        make.centerY.equalTo(self.TopimageV.mas_centerY);
    }];

    [self.topV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top);
        make.bottom.equalTo(self.TopimageV.mas_top);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
    }];

    [self.bottomV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.mas_bottom);
        make.top.equalTo(self.classV.mas_bottom);
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
    }];

    [self.leftV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.classV.mas_left);
        make.top.equalTo(self.topV.mas_bottom);
        make.bottom.equalTo(self.bottomV.mas_top);
    }];

    [self.rightV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.topV.mas_bottom);
        make.bottom.equalTo(self.bottomV.mas_top);
        make.left.equalTo(self.classV.mas_right);
        make.right.equalTo(self.mas_right);
    }];
}

-(void)hiddenV
{
    [UIView animateWithDuration:0.3 animations:^{
        self.alpha = 0;
    }];
}


@end
